package avicit.bdp.dms.das.rest;

import avicit.bdp.dms.das.dto.BdpDasLinkDTO;
import avicit.bdp.dms.das.service.BdpDasLinkService;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 数据模型关系管理REST接口
 */
@RestController
@Api(tags = "数据模型关系管理REST接口")
@RequestMapping("/api/bdp/dms/das/link")
public class BdpDasLinkRest {

    private static final Logger LOGGER = LoggerFactory.getLogger(BdpDasLinkRest.class);

    @Autowired
    private BdpDasLinkService bdpDasLinkService;



    /**
     * 保存模型关系对象
     */
    @ApiOperation(value = "保存对象")
    @PostMapping("/saveLinkImages")
    public ResponseMsg<String> saveLinkImages(@RequestBody List<BdpDasLinkDTO> links) {
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        bdpDasLinkService.updateBdpDasLink(links);
        return responseMsg;
    }

    /**
     * 新增模型关系对象
     * @param bdpDasLink
     * @return
     */
    @ApiOperation(value = "新增对象")
    @PostMapping("/insertLinkImage")
    public ResponseMsg<BdpDasLinkDTO> insertLinkImage(@RequestBody BdpDasLinkDTO bdpDasLink) {
        ResponseMsg<BdpDasLinkDTO> responseMsg = new ResponseMsg<>();
        bdpDasLink.setOrgIdentity(ThreadContextHelper.getOrgId());
        responseMsg.setResponseBody(bdpDasLinkService.insertBdpDasLink(bdpDasLink));
        return responseMsg;
    }

    /**
     * 删除模型关系对象
     */
    @ApiOperation(value = "按主键批量删除")
    @ApiImplicitParam(name = "ids", value = "id集合", dataType = "List", paramType = "body", required = true)
    @PostMapping("/deleteLinkLine")
    public ResponseMsg<Integer> deleteById(@RequestBody List<String> ids) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        bdpDasLinkService.deleteBdpDasLinkById(ids);
        return responseMsg;
    }
}